//
//  RQQZCell.m
//  yigou
//
//  Created by SunChao on 17/1/11.
//  Copyright © 2017年 hanyiwang. All rights reserved.
//

#import "RQQZCell.h"

@implementation RQQZCell
-(void)awakeFromNib
{
    [super awakeFromNib];
    [self.FocusBtn setBackgroundColor:QINGColor];
    self.FocusBtn.layer.cornerRadius = 5;
    self.FocusBtn.layer.masksToBounds = YES;
    [self.FocusBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.FocusBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    
    [self.FocusBtn setTitle:@"+关注" forState:UIControlStateNormal];
    [self.FocusBtn setTitle:@"已关注" forState:UIControlStateSelected];
}
-(void)setModel:(RQQZModel *)model
{
    _model = model;
    
    self.nameLabel.text = model.nick_name;
    [self.bgImg sd_setImageWithURL:[NSURL URLWithString:model.head_url] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    self.bgImg.layer.cornerRadius = 30;
    self.bgImg.layer.masksToBounds = YES;
    self.desc.text = model.user_signature;
}

- (IBAction)FocusAction:(UIButton *)sender {
    NSLog(@"点击了");
    if (self.FocusBtn.selected ==YES) {
        return;
    }else{
        [self loadNetworkData];
        
    }
}

- (void)loadNetworkData {
    
    DYBaseRequest *request = [DYBaseRequest new];
    NSString *url = [NSString stringWithFormat:@"%@/hytribe/setConcern?follow_obj_id=%@", APIYIGOU, _model.user_id ];
    request.requestUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSLog(@"------%@",request);
    [ViewFactory showSuccess:@"关注成功"];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"GuanZhuRQQZ" object:nil];
    } error:^(YTKBaseRequest *request) {
        NSData *JSONData = [request.responseString dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableLeaves error:nil];
        [ViewFactory showErrorStrMsg:[responseJSON objectForKey:@"message"]];
    } failure:^(YTKBaseRequest *request) {
        [ViewFactory showErrorStrMsg:NETWORK_ERR];
        
    }];
}
- (void)dealloc{
    
}
@end
